package com.xmall.pethouse_api.service.impl;

import com.xmall.pethouse_api.mapper.PetMapper;
import com.xmall.pethouse_api.pojo.entity.Pet;
import com.xmall.pethouse_api.pojo.dto.AddPetDto;
import com.xmall.pethouse_api.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class PetServiceImpl implements PetService {

    @Autowired
    private PetMapper petMapper;

    @Override
    public List<Pet> findByOwnerId(Long ownerId) {
        return petMapper.findByOwnerId(ownerId);
    }
    
    @Override
    public Pet addPet(AddPetDto addPetDto, Long ownerId) {
        Pet pet = new Pet();
        pet.setOwnerId(ownerId);
        pet.setName(addPetDto.getName());
        pet.setType(addPetDto.getType());
        pet.setBreed(addPetDto.getBreed());
        pet.setAge(addPetDto.getAge());
        pet.setGender(addPetDto.getGender());
        pet.setWeight(addPetDto.getWeight());
        pet.setPhotoUrls(addPetDto.getPhotoUrls());
        pet.setCreatedAt(LocalDateTime.now());
        pet.setUpdatedAt(LocalDateTime.now());
        
        petMapper.insert(pet);
        return pet;
    }
    
    // ...（可扩展其它方法）
} 